import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/views/layout";
import Login from "@/views/login"

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/userManage",
    name: "userManage",
    component: (resolve) => require(["@/views/customer/userManage"], resolve),
  },
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: (resolve) => require(["@/views/redirect"], resolve),
      },
    ],
  },
  {
    path: "",
    component: Layout,
    redirect: "index",
    children: [
      // {
      //   path: "index",
      //   component: (resolve) => require(["@/views/home"], resolve),
      //   name: "首页",
      //   meta: {title: "首页", icon: "", affix: true},
      // },
      {
        path: "index",
        name: "index",
        component: (resolve) => require(["@/views/home"], resolve),
      },
      {
        path: "/petPreview",
        name: "petPreview",
        component: (resolve) => require(["@/views/customer/petPreview"], resolve),
      },
      {
        path: "/servicePreview",
        name: "servicePreview",
        component: (resolve) => require(["@/views/customer/servicePreview"], resolve),
      },
      {
        path: "/careAppointment",
        name: "careAppointment",
        component: (resolve) => require(["@/views/customer/careAppointment"], resolve),
      },
      {
        path: "/staffManage",
        name: "staffManage",
        component: (resolve) => require(["@/views/staff/staffManage"], resolve),
      },
      {
        path: "/performanceManage",
        name: "performanceManage",
        component: (resolve) => require(["@/views/staff/performanceManage"], resolve),
      },
      {
        path: "/orderManage",
        name: "orderManage",
        component: (resolve) => require(["@/views/staff/orderManage"], resolve),
      },
      {
        path: "/petManage",
        name: "petManage",
        component: (resolve) => require(["@/views/staff/petManage"], resolve),
      },
      {
        path: "/serviceManage",
        name: "serviceManage",
        component: (resolve) => require(["@/views/staff/serviceManage"], resolve),
      },
    ],
  }
];

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  routes,
});

export default router;
